<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加角色</legend>
</fieldset>
<div class="layui-form-item">
    <div class="layui-inline" >
        <form class="layui-form"  >
            <div class="layui-form-item">
                <label class="layui-form-label">角色标识</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="name|required" lay-reqtext="角色标识是必填项"   placeholder="角色标识" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">注释</label>
                <div class="layui-input-inline">
                    <input type="text" name="description" lay-verify="required"  placeholder="昵称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="roleForm">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script  src="../../../layui/layui.js" ></script>
<script src="../../../layui/layui.all.js"  ></script>
<script src="../../../js/jquery.min.js"></script>

<script>
    layui.use('table', function() {
        var form = layui.form;
        var layer = layui.layer;
        //自定义验证规则
        form.verify({
            name: function(value){
                if(!(/^[a-z]+$/i.test(value))){
                    return '只能为英文';
                }
            }
        });
        //监听提交
        form.on('submit(roleForm)', function(data){
            $.ajax({
                url:"/sysRole/saveRole",
                method:"post",
                data:data.field,
                success:function(data){
                    if(data.code== 404 ){
                        layer.msg(data.msg);
                    }else {
                        layer.msg(data.msg);
                        setTimeout(function(){
                            layer.close(layer.index);
                            window.parent.location.reload();
                        },1800 );

                    }
                }
            });
        });
    })
</script>
</body>
</html>